package cn.bone.web.controller;

import cn.bone.web.bean.Member;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by MD-01 on 2017/4/14.
 */
@Controller
public class MainController {

    @RequestMapping("/")
    public String index(){
        return "login";
    }

    @RequestMapping("/welcome")
    public String welcome(){
        return "welcome";
    }

    @RequestMapping("/login")
    public String login(){
        return "login";
    }

    @RequestMapping("/member/login")
    public String doLogin(String username, String password, HttpServletRequest request){

        if(StringUtils.isEmpty(username)){
            request.setAttribute("error","用户名不能为空");
            return "/login";
        }
        if(StringUtils.isEmpty(password)){
            request.setAttribute("error","密码不能为空");
            return "/login";
        }
        if(!username.equals("admin")||!password.equals("admin")){
            request.setAttribute("error","用户名或密码错误");
            return "/login";
        }
        Member member = new Member();
        member.setUsername("admin");
        member.setPassword("admin");
        request.getSession().setAttribute("user",member);
        return "redirect:/main";
    }
    @RequestMapping("/main")
    public String main(){
        return "main";
    }
}
